package main

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
	"time"
)

func main() {
	conn, err := redis.Dial("tcp", "100.100.142.112:6379")

	if err != nil {
		fmt.Println("Connect to redis error", err)
		return
	} else {
		fmt.Println("Connect to redis ok.")
	}

	defer conn.Close()

	/*	for i := 0; i < 10; i++ {
		_, err = conn.Do("ZADD", "mykey", "INCR", i, fmt.Sprintf("robot2_%d", i))
		if err != nil {
			fmt.Println("redis set failed:", err)
		}
	}*/

	//zrangebyscore key min max [withscores] [limit offset count]
	//返回有序集 key 中，所有score值介于min和max 之间(包括等于min或max )的成员
	//reply, err := conn.Do("zrangebyscore", "radar_target", 1655891960312, 1655891993312, "withscores")

	et := time.Now().UnixMilli()
	st := et - 80
	//reply, err := conn.Do("zrevrangebyscore", "radar_target", et, st, "withscores")
	reply, err := conn.Do("zrevrangebyscore", "radar_target", et, st)
	fmt.Println(reply)

	//ZRANGE按下标查询
	//reply, err := conn.Do("ZRANGE", "radar_target", 0, 20, "withscores")

	/*user_map, err := redis.StringMap(conn.Do("ZRANGE", "radar_target_test", 1654914110732, 1654914114732, "withscores"))
	if err != nil {
		fmt.Println("redis get failed:", err)
	} else {
		fmt.Printf("Get mykey: %v \n", user_map)
	}

	for user := range user_map {
		fmt.Printf("user name: %v %v\n", user, user_map[user])
	}*/
}
